From 02e7dc8e378ce656f09b58abcaea5691683e29ef Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 15 Feb 2015 20:45:59 -0800 Subject: [PATCH] Don't discard docopt error information Not sure why we were doing this, it's quite useful! Closes #1297 --- src/cargo/lib.rs | 7 +------ tests/test_cargo_new.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index d5737efd9..249ded37c 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -210,12 +210,7 @@ fn flags_from_args<'a, T>(usage: &str, args: &[String], .version(Some(version())); docopt.decode().map_err(|e| { let code = if e.fatal() {1} else {0}; - let desc = match e { - docopt::Error::WithProgramUsage(_, s) => s, - ref e if e.fatal() => e.description().to_string(), - e => e.to_string(), - }; - CliError::from_error(human(desc), code) + CliError::from_error(human(e.to_string()), code) }) } diff --git a/tests/test_cargo_new.rs b/tests/test_cargo_new.rs index 0b268916a..760c5d89f 100644 --- a/tests/test_cargo_new.rs +++ b/tests/test_cargo_new.rs @@ -72,6 +72,8 @@ test!(no_argument { assert_that(cargo_process("new"), execs().with_status(1) .with_stderr("\ +Invalid arguments. + Usage: cargo new [options] cargo new -h | --help @@ -189,3 +191,15 @@ test!(subpackage_no_git { assert_that(&paths::root().join("foo/components/subcomponent/.gitignore"), is_not(existing_file())); }); + +test!(unknown_flags { + assert_that(cargo_process("new").arg("foo").arg("--flag"), + execs().with_status(1) + .with_stderr("\ +Unknown flag: '--flag' + +Usage: + cargo new [..] + cargo new [..] +")); +}); -- 2.30.2